import {useState} from 'react'
import { useList } from '../../context/ListProvider';


const AddItem = () => {
    
  const {dispatch} = useList();
  const [value,setValue] = useState()
  const onChange= e=>setValue(e.target.value)

  const handleAdd=()=>{
    dispatch({type:'add_item',value})
  }

  return (
    <div>
        <input 
          type="text" 
          value = {value}
          onChange={onChange}
        />
        <button onClick={handleAdd}>添加</button>
    </div>
  )
}

export default AddItem